function KFLast = fillFG(paths_current,dataStru_Current,model_current,filterStru_current)
% This function will fill in both the extra Forward Guidance terms as well
% as rewrite the second sample priors in terms of the posterior means.
%
% Currently, it will get the data for the estimation you are running now.
%
% Last Edited: 5/19/2014 by TM
%% Load structures of estimation 
cd(paths_current.WorkLoc);
load workspace; 
cd(paths_current.cucd);

%% Load Blank Priors
% Load XLS match NAN with estimated Parameter Values 
cd(paths_current.loadBlankLoc)
[~,~,Out.S2Prior] = xlsread(paths_current.loadBlankBook,paths_current.loadBlankSheet);
cd(paths_current.cucd)

% Change "NaN's" in the Excel Sheet to NaN's in MATLAB.
% Note that I am just looking for strings, so be careful here.
Out.ReWriteParam = cell2mat(cellfun(@(x)(isa(x,'char')),Out.S2Prior(:,3),'UniformOutput',false));
Out.S2Prior(Out.ReWriteParam,3) = {nan};

%% Fill in the NAN with estimated values 
% Fill in.  Note that we only want to fill in the parameters that we have
% not changed.
Out.NanParam = Out.S2Prior(Out.ReWriteParam,1);
Out.S2Prior(ismember(Out.S2Prior(:,1),Out.NanParam),3) = num2cell(model.param(ismember(parnames,Out.NanParam)));

% Check if any nans
Temp.CheckNan = isnan(cell2mat(Out.S2Prior(:,3)));
if any(Temp.CheckNan)
    Temp.NanLoc = find(Temp.CheckNan);
    for i = 1:numel(Temp.NanLoc)
    fprintf('NaN at location %1.0f',Temp.NanLoc(i));
    end
    error(['Check NaN''s in ' paths_current.loadBlankBook])
end

%% Get Starting Values for Second Sample
% There are five inputs to the Kalman Filter Splits function:
%   1) model.param  --> This one will have to change to reflect the larger
%   parameter space.
%   2) model        --> This is used for the following subcategories, which
%   are going to not have to be changed.  
%       a) handle       --> Location of the mod File.
%       b) solveOptions --> Solve Options
%       c) addsol       --> AddSol
%   3) dataStru     --> The Data, we can reuse what we had before.
%   4) flags        --> Different options, we can reuse what we had before.
%   5) filterStru   --> CAN WE USE THIS STILL????

% Load data with N FG 
if isempty(dataStru_Current.fileName)==true 
    error('dataStru.fileName is empty! Not loading data') 
end 

dataStru_Current.fileName = paths_current.NewDataFileName;

cd(dataStru_Current.loadPath);
[dataStru_Current.Y,dataStru_Current.Ynames,datatru.sample,dataStru_Current.trainvec]=...
    load_dset(dataStru_Current.fileName,dataStru_Current.loadPath,dataStru_Current,...
    dataStru_Current.demeanType,flags.onscreen);
cd(paths_current.cucd);

dataStru_Current.data = dataStru_Current.Y;
Out.fullParVec = cell2mat(Out.S2Prior(:,3));

% Change to First Sample
dataStru_Current.trainVec = dataStru.trainVec;

% Run KFilter 
[KFStru,~]=feval(filterStru_current.funcKfilter,Out.fullParVec,model_current,dataStru_Current,flags,filterStru);
cd(paths_current.loadBlankLoc);
save workspace;

KFLast.aZero=KFStru.aLast;
KFLast.pZero=KFStru.pLast;
KFLast.aZeroDecomp=squeeze(KFStru.countSt(end,:,:));
save KFLast KFLast;
disp('Saved KFLast with aZero, pZero and aZeroDecomp');
cd(paths_current.cucd);

% =========================================================================
%% Create XLS file with 
%  Prior 
%  Set Starting value to newly created extended parameter 
% =========================================================================
cd(paths_current.loadBlankLoc)
xlswrite('S2Prior - S1',Out.S2Prior)
cd(paths_current.cucd)






end